import { OneNETAPI } from "../../utils/OneNETAPI/OneNETAPI"
const OneNET = new OneNETAPI('sl5gkKWYKYCShqiS7egDu==pJ3c=')
const app = getApp<IAppOption>()

Page({
  data: {
    inputs: '',
    title: ''
  },
  onLoad: function (options) {
    let date = new Date()
    let str = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
    this.setData({ title: str })
  },
  titleChange(e: any) {
    this.data.title = e.detail.value
  },
  change(e: any) {
    this.data.inputs = e.detail.value
  },
  buttonTap() {
    if (this.data.inputs == '') {
      wx.showToast({
        title: '请输入回复内容',
        icon: 'none'
      })
    }
    else {
      OneNET.sendCommand({
        device_id: app.globalData.UserId,
        command: this.data.title + ':' + this.data.inputs,
        args: {
          qos: 0,
          timeout: 100,
        },
        successcb: function (res) {
          console.log(res)
          if (res.errno != 0) {
            wx.showToast({
              title: '回复失败',
              icon: 'none'
            })
          }
          else {
            wx.showToast({
              title: '回复成功'
            })
          }
        },
        failcb: function (res) {
          wx.showToast({
            title: '回复失败',
            icon: 'none'
          })
        }
      })
    }
  }
})